1. /* ceilpow2.cpp by K.Tsuru */
  2. // function ID = 001
  3. /*********************************************************************************
  4. SN library sub-function
  5. Return a value k which satisfies a condition sz<=k (k = 2^n).
  6. If sz*2 > UINT_MAX=4294967295(32 bits system),
  7. return a value INT_MAX+1 = 2147483648L = 2^31.
  8. **********************************************************************************/
  9. #include <limits.h>
  10. unsigned int ceilpow2(unsigned int sz){
  11. if(sz < 2u) return 1u;
  12. if(sz > UINT_MAX/2u) return (unsigned int)INT_MAX+1u;
  13. unsigned int k = 2u;
  14. while(k < sz) k *= 2u;
  15. return k;
  16. }

ceilpow2.cpp : last modifiled at 2017/02/17 10:34:24(623 bytes)
created at 2016/04/11 11:17:20
The creation time of this html file is 2017/10/07 10:54:15 (Sat Oct 07 10:54:15 2017).